﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RM2012Server.Model;
using System.Data;
using RM2012Server.Business;
using DevComponents.DotNetBar.Controls;
using System.Windows.Forms;

namespace RM2012Server.Controller
{
    public class PermissionCtrl
    {
        PermissionDAO m_PermissionDAO = new PermissionDAO();

        public void Show(DataGridViewX dgv, BindingNavigator bn)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = GetAll();
            bn.BindingSource = bs;
            dgv.DataSource = bs;
        }

        public void Show(DataGridViewX dgv,
                         BindingNavigator bn,
                         ComboBoxEx cmbUser,
                         ComboBoxEx cmbGroup)
        {
            BindingSource bs = new BindingSource();
            bs.DataSource = GetAll();

            cmbUser.DataBindings.Clear();
            cmbUser.DataBindings.Add("SelectedValue", bs, "UserId");

            cmbGroup.DataBindings.Clear();
            cmbGroup.DataBindings.Add("SelectedValue", bs, "UserGroupId");

            bn.BindingSource = bs;
            dgv.DataSource = bs;
        }

        public DataTable GetAll()
        {
            return m_PermissionDAO.GetAll();
        }

        public int Add(PermissionInfo info)
        {
            return m_PermissionDAO.Add(info);
        }

        public int Update(PermissionInfo info)
        {
            return m_PermissionDAO.Update(info);
        }

        public int DeleteByUser(String userId)
        {
            return m_PermissionDAO.DeleteByUser(userId);
        }

        public int DeleteByGroup(String userGroupId)
        {
            return m_PermissionDAO.DeleteByGroup(userGroupId);
        }

        public DataRow AddNewRow()
        {
            return m_PermissionDAO.AddNewRow();
        }

        public void AddNewPermission(DataRow m_Row)
        {
            m_PermissionDAO.AddNewPermission(m_Row);
        }

        public bool SaveData()
        {
            return m_PermissionDAO.SaveData();
        }
    }
}
